package com.cloud.pole.common.util;

import java.math.BigDecimal;

import org.apache.commons.lang3.StringUtils;

public class RegexUtils {
	
	public final static String MOBILE_AREA_CHINA = "86";
	
	public RegexUtils() {
	}
	/**
	 * 验证图片文件
	 * @param strMsg
	 * @return
	 */
	public static boolean isImageFile(String strMsg) {
		boolean bFlag = false;
		String strReg = "";
		try {
			if(strMsg == null || strMsg.equals("")){
				bFlag = false;
			}
			else{
				strReg = ".+(.jpeg|.jpg|.png)$";  
				if (strMsg.toLowerCase().matches(strReg)){
					bFlag = true;
				}
			}
		
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	/**
	 * 验证是否手机号码
	 * 
	 * @param strMobile
	 * @return
	 */
	public static boolean isMobileNo(String strMobile, String strMobileArea) {
		boolean bFlag = false;
		String strReg = "";
		try {
			if(StringUtils.isEmpty(strMobile) || StringUtils.isEmpty(strMobileArea)){
				return false;
			}
			//china
			if(StringUtils.equals(strMobileArea, "86")){
				strReg = "^[1-9]\\d{10}";
			}
			//中国香港
			else if(StringUtils.equals(strMobileArea, "852")){
				strReg = "^([1-9])\\d{7}$";
			}
			//中国澳门
			else if(StringUtils.equals(strMobileArea, "853")){
				strReg = "^([1-9])\\d{7}$";
			}
			//中国台湾
			else if(StringUtils.equals(strMobileArea, "886")){
				strReg = "^09\\d{8}$";
			}
			//其他情况
			else{
				strReg = "^\\d+$";
			}
			if (strMobile.matches(strReg)){
				bFlag = true;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	/**
	 * 正数、负数、和小数
	 * @param strMsg
	 * @return
	 */
	public static boolean isNumberString(String strMsg) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^(\\-|\\+)?\\d+(\\.\\d+)?$";
			if (strMsg.matches(strReg))
				bFlag = true;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}

	/**
	 * 验证负整数
	 * @param strMsg
	 * @return
	 */
	public static boolean isNegtiveInteger(String strMsg) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^-[0-9]*[1-9][0-9]*$";
			if (strMsg.matches(strReg))
				bFlag = true;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	/**
	 * 验证非负整数（正整数   + 0） 
	 * @param strMsg
	 * @return
	 */
	public static boolean isNotNegtiveInteger(String strMsg) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^\\d+$";
			if (strMsg.matches(strReg))
				bFlag = true;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}


	/**
	 * 验证正整数
	 * @param strMsg
	 * @return
	 */
	public static boolean isPositiveInteger(String strMsg) {
		boolean bFlag = false;
		String strReg = "";
		try {
			if(strMsg == null || strMsg.equals("")){
				return bFlag;
			}
			strReg = "^[0-9]*[1-9][0-9]*$";
			if (strMsg.matches(strReg))
				bFlag = true;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	/**
	 * 验证非正整数（负整数   +  0）
	 * @param strMsg
	 * @return
	 */
	public static boolean isNotPositiveInteger(String strMsg) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^((-\\d+)|(0+))$";
			if (strMsg.matches(strReg))
				bFlag = true;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	/**
	 * 验证整数
	 * @param strMsg
	 * @return
	 */
	public static boolean isInteger(String strMsg) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^-?\\d+$";
			if (strMsg.matches(strReg))
				bFlag = true;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	/**
	 * 验证是否正确邮箱地址
	 * 
	 * @param strMobile
	 * @return
	 */
	public static boolean isEmail(String strEmail) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
			if(strEmail == null){
				bFlag = false;
			}
			else if (strEmail.matches(strReg)){
				bFlag = true;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	
	/**
	 * 验证是否正确的登录密码
	 * 
	 * @param strLoginPwd
	 * @return
	 */
	public static boolean isRightLoginPwd(String strLoginPwd) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$";
			if(strLoginPwd == null){
				bFlag = false;
			}
			else if (strLoginPwd.matches(strReg)){
				bFlag = true;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	
	/**
	 * 验证是否正确的钱包密码
	 * 
	 * @param strLoginPwd
	 * @return
	 */
	public static boolean isRightWalletPwd(String strWalletPwd) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$";
			if(strWalletPwd == null){
				bFlag = false;
			}
			else if (strWalletPwd.matches(strReg)){
				bFlag = true;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	/**
	 * 是否正确的转账金额(小数点前20位,小数点后的20位并且大于0)
	 * @param strMsg
	 * @return
	 */
	public static boolean isRightTransfAmount(String strMsg) {
		boolean bFlag = false;
		String strReg = "";
		try {
			strReg = "^([1-9][0-9]{0,19}(\\.[0-9]{1,20})?)|(0\\.[0-9]{1,20})$";
			if(strMsg == null){
				bFlag = false;
			}
			else if (strMsg.matches(strReg)){
				//验证大于0
				BigDecimal bgMsg = new BigDecimal(strMsg);
				if(bgMsg.doubleValue() > 0){
					bFlag = true;
				}
			}
			else{
				bFlag = false;
			}
		} catch (Exception ex) {
			bFlag = false;
			ex.printStackTrace();
		}
		// System.out.println("strMobile["+strMobile+"]-" + bFlag);
		return bFlag;
	}
	
	public static void main(String[] args) {
		String strReg = "^[a-zA-Z\\\\\\\\d]+/admin/[a-zA-Z\\\\\\\\d]+$";
		String msg = "/api/msg/verifyCode/admin/test";
		System.out.println(msg.matches(strReg));
	}
}
